package com.example.orderserver.feign;

import com.example.orderserver.callback.ProductFeignCallBack;
import com.example.orderserver.callback.ProductFeignCallBackFactory;
import com.example.productserverapi.entity.Product;
import com.netflix.client.ClientException;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.cloud.openfeign.SpringQueryMap;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.Map;

/**
 * @author benjamin_5
 * @Description
 * @date 2023/3/8
 */
@FeignClient(name = "product-server",
        contextId="product-server-nacos",
        path = "product",
        qualifier = "product-nacos",
//        decode404 = true,
        fallbackFactory = ProductFeignCallBackFactory.class)
public interface ProductFeignNacos {

    String PREFIX = "";
//    String PREFIX = "product"; // 相当于path="product"
    String GET_INFO = PREFIX + "/getInfo";
    String GET_BY_NAME = PREFIX + "/getByName";
    String GET_BY_BODY = PREFIX + "/getByBody";
    String GET_BY_BODY2 = PREFIX + "/getByBody2";
    String GET_BY_BODY3 = PREFIX + "/getByBody3";

    @GetMapping(GET_INFO)
    String getInfo() throws ClientException;

    @GetMapping(GET_BY_NAME)
    String getByName(@RequestParam("name") String name);

    @PostMapping(GET_BY_BODY)
    String getByBody(Product product);

    /**
     *
     * @param
     * @return
     */
    @GetMapping(GET_BY_BODY2)
    String getByBody2(@RequestParam("product") Map product);

    /**
     *
     * @param
     * @return
     */
    @GetMapping(GET_BY_BODY2)
    String getByBody3(@SpringQueryMap Product product);


    /**
     * 此方式需要添加feign-httpclient依赖
     * @param product
     * @return
     */
    @GetMapping(value = GET_BY_BODY3)
    String getByBody4(Product product);
}
